<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>安装linux实验环境 | 月藤的博客</title>
    <meta name="generator" content="VuePress 1.8.0">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css">
    <meta name="description" content="简单的介绍">
    
    <link rel="preload" href="/assets/css/0.styles.a2e941e0.css" as="style"><link rel="preload" href="/assets/js/app.54ea76a2.js" as="script"><link rel="preload" href="/assets/js/2.c554ece5.js" as="script"><link rel="preload" href="/assets/js/15.1adeebc5.js" as="script"><link rel="prefetch" href="/assets/js/10.95d63e51.js"><link rel="prefetch" href="/assets/js/11.26e082be.js"><link rel="prefetch" href="/assets/js/12.1f62021c.js"><link rel="prefetch" href="/assets/js/13.9096527c.js"><link rel="prefetch" href="/assets/js/14.86142c70.js"><link rel="prefetch" href="/assets/js/16.efcc79e4.js"><link rel="prefetch" href="/assets/js/17.74da5698.js"><link rel="prefetch" href="/assets/js/18.fd808b3a.js"><link rel="prefetch" href="/assets/js/19.8dafe26f.js"><link rel="prefetch" href="/assets/js/20.aed54ab4.js"><link rel="prefetch" href="/assets/js/21.341a5670.js"><link rel="prefetch" href="/assets/js/22.ab8b375c.js"><link rel="prefetch" href="/assets/js/23.28489470.js"><link rel="prefetch" href="/assets/js/24.87aae001.js"><link rel="prefetch" href="/assets/js/25.211ca3bf.js"><link rel="prefetch" href="/assets/js/26.afa4c8f0.js"><link rel="prefetch" href="/assets/js/27.9b98f6f3.js"><link rel="prefetch" href="/assets/js/28.93298733.js"><link rel="prefetch" href="/assets/js/29.e8c038c4.js"><link rel="prefetch" href="/assets/js/3.9d562ae1.js"><link rel="prefetch" href="/assets/js/30.27939f01.js"><link rel="prefetch" href="/assets/js/31.6a9774e8.js"><link rel="prefetch" href="/assets/js/32.f698e967.js"><link rel="prefetch" href="/assets/js/33.5ba4bfb8.js"><link rel="prefetch" href="/assets/js/34.dca90861.js"><link rel="prefetch" href="/assets/js/35.768c1bb2.js"><link rel="prefetch" href="/assets/js/36.6b0a867f.js"><link rel="prefetch" href="/assets/js/37.61156e90.js"><link rel="prefetch" href="/assets/js/38.e390246c.js"><link rel="prefetch" href="/assets/js/39.0fbd0dd1.js"><link rel="prefetch" href="/assets/js/4.e18bc6a8.js"><link rel="prefetch" href="/assets/js/40.4252699c.js"><link rel="prefetch" href="/assets/js/41.2e5b5840.js"><link rel="prefetch" href="/assets/js/42.8fe886c7.js"><link rel="prefetch" href="/assets/js/43.7a4b0851.js"><link rel="prefetch" href="/assets/js/44.93c2313d.js"><link rel="prefetch" href="/assets/js/45.33dcea60.js"><link rel="prefetch" href="/assets/js/46.681fdf10.js"><link rel="prefetch" href="/assets/js/47.a842a141.js"><link rel="prefetch" href="/assets/js/48.9a03ba74.js"><link rel="prefetch" href="/assets/js/49.a50266b1.js"><link rel="prefetch" href="/assets/js/5.dc6a2d8c.js"><link rel="prefetch" href="/assets/js/50.f2a42406.js"><link rel="prefetch" href="/assets/js/51.444cc3d8.js"><link rel="prefetch" href="/assets/js/52.cf2befd8.js"><link rel="prefetch" href="/assets/js/53.fbe609f8.js"><link rel="prefetch" href="/assets/js/54.a43fb514.js"><link rel="prefetch" href="/assets/js/55.d0c11641.js"><link rel="prefetch" href="/assets/js/56.c6f114d9.js"><link rel="prefetch" href="/assets/js/57.cc386420.js"><link rel="prefetch" href="/assets/js/58.e747d0f6.js"><link rel="prefetch" href="/assets/js/6.c1fd48f0.js"><link rel="prefetch" href="/assets/js/7.32b39b92.js"><link rel="prefetch" href="/assets/js/8.e2284671.js"><link rel="prefetch" href="/assets/js/9.8def3992.js">
    <link rel="stylesheet" href="/assets/css/0.styles.a2e941e0.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">月藤的博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="https://ziphold.gitee.io/blog/#/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  旧博客（停止更新）
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://rattonlzh.github.io/homepage/homepage.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  常用网址导航（停止更新）
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Select language" class="dropdown-title"><span class="title">Languages</span> <span class="arrow down"></span></button> <button type="button" aria-label="Select language" class="mobile-dropdown-title"><span class="title">Languages</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/配置记录/安装linux虚拟机.html" class="nav-link">
  zh-CN
</a></li><li class="dropdown-item"><!----> <a href="/en/" class="nav-link">
  en-US
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><div class="avatar"><img src="/assets/img/avatar.2b77755b.png" alt srcset></div> <div style="z-index: 999"><iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="298" height="52" src="//music.163.com/outchain/player?type=2&id=28283137&auto=1&height=32"></iframe></div> <nav class="nav-links"><div class="nav-item"><a href="https://ziphold.gitee.io/blog/#/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  旧博客（停止更新）
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://rattonlzh.github.io/homepage/homepage.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  常用网址导航（停止更新）
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Select language" class="dropdown-title"><span class="title">Languages</span> <span class="arrow down"></span></button> <button type="button" aria-label="Select language" class="mobile-dropdown-title"><span class="title">Languages</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/配置记录/安装linux虚拟机.html" class="nav-link">
  zh-CN
</a></li><li class="dropdown-item"><!----> <a href="/en/" class="nav-link">
  en-US
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>随便说说</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>知识点总结</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>考研专区</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>读书笔记</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>开发资料</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>配置记录</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/配置记录/apache服务器配置.html" class="sidebar-link">apache服务器配置</a></li><li><a href="/配置记录/elicpse配置.html" class="sidebar-link">elicpse配置</a></li><li><a href="/配置记录/install-sogou-im.html" class="sidebar-link">ubuntu18.04下安装搜狗输入法</a></li><li><a href="/配置记录/LAMP安装记.html" class="sidebar-link">LAMP实训</a></li><li><a href="/配置记录/lnmp安装.html" class="sidebar-link">一条命令开启lnmp</a></li><li><a href="/配置记录/Ubuntu１８．０４新手踩雷.html" class="sidebar-link">ubuntu18.04 新手踩雷</a></li><li><a href="/配置记录/安装linux虚拟机.html" class="active sidebar-link">安装linux实验环境</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/配置记录/安装linux虚拟机.html#服务器服务一键启动脚本" class="sidebar-link">服务器服务一键启动脚本</a></li></ul></li><li><a href="/配置记录/运行tensorflow使用gpu加速.html" class="sidebar-link">运行tensorflow使用gpu加速</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>思维导图</span> <span class="arrow right"></span></p> <!----></section></li><li><a href="/friend_link.html" class="sidebar-link">友情链接</a></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="安装linux实验环境"><a href="#安装linux实验环境" class="header-anchor">#</a> 安装linux实验环境</h1> <ol><li><p>安装virtual box</p></li> <li><p>安装ubuntu18.04,用户名为ratton</p> <p>mirrors：https://mirrors.tuna.tsinghua.edu.cn/ubuntu/</p></li> <li><p>配置网络</p> <p>注意连接方式为桥接网卡，如果是连wifi上网，则选中带有wireless的；如果是插网线的，则选中controller</p> <p><img src="/assets/img/virtualbox网络设置.d0266ce2.png" alt=""></p></li> <li><p>设置静态路由</p> <div class="language- extra-class"><pre class="language-text"><code> sudo vi /etc/netplan/50-cloud-init.yaml
</code></pre></div><div class="language- extra-class"><pre class="language-text"><code>network:
    ethernets:
        enp0s3:
            dhcp4: false
            addresses:
                - 192.168.0.233/24
            gateway4: 192.168.0.1
            nameservers:
                addresses: [192.168.0.1]

    version: 2
</code></pre></div><p>使应用生效</p> <div class="language- extra-class"><pre class="language-text"><code>sudo netplan apply
</code></pre></div></li> <li><p>修改宿主机hosts</p> <p>添加到<code>C:\Windows\System32\drivers\etc\hosts</code>文件行尾</p> <div class="language- extra-class"><pre class="language-text"><code>192.168.0.233 ubuntu
</code></pre></div></li> <li><p>windows terminal远程登录</p></li></ol> <div class="language- extra-class"><pre class="language-text"><code>ssh ratton@ubuntu
</code></pre></div><ol start="7"><li>设置时区</li></ol> <div class="language- extra-class"><pre class="language-text"><code>timedatectl set-timezone Asia/Shanghai
</code></pre></div><ol start="8"><li><p>给Linux扩容</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">fdisk</span> -l<span class="token comment">#查看物理磁盘使用情况</span>
<span class="token function">du</span> -lh<span class="token comment">#查看逻辑卷使用情况</span>
</code></pre></div><p><img src="/assets/img/image-20200806210303875.629b41ec.png" alt="image-20200806210303875"></p> <p><img src="/assets/img/image-20200806210138465.4c735c03.png" alt="image-20200806210138465"></p> <p><code>/dev/mapper/ubuntu--vg-ubuntu--lv</code>这玩意空间不足了，为啥，因为lv只分配了4G实际上，你还有几十G的空闲磁盘没有被使用，所以接下来要做的就是把空闲的磁盘挂载到lv上</p> <div class="language-bash extra-class"><pre class="language-bash"><code> <span class="token function">sudo</span> vgdisplay	
</code></pre></div><p><img src="/assets/img/image-20200806210728824.9a55c56a.png" alt="image-20200806210728824"></p> <p>可以看到有45G左右的空闲磁盘可以用于扩容</p> <p>扩容命令</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">sudo</span> lvextend -L 10G /dev/mapper/ubuntu--vg-ubuntu--lv<span class="token comment">#给lv扩容10G</span>
</code></pre></div><p><img src="/assets/img/image-20200806211020745.00fd7283.png" alt="image-20200806211020745"></p> <p>也可以将空闲磁盘全部用于扩容</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">sudo</span> lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv	
</code></pre></div><p>此时使用<code>df -h</code>发现并没有变化，我们需要手动执行重新计算磁盘大小的命令</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">sudo</span> resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
</code></pre></div><p><img src="/assets/img/image-20200806211433556.38dda42e.png" alt="image-20200806211433556"></p> <p>可以看到lv的size从原来的3.9G扩容到了现在的9.8G</p></li> <li><p>配置ssh公钥实现免密登录</p> <p>在宿主机上生成公钥</p> <div class="language-bash extra-class"><pre class="language-bash"><code>ssh-keygen
</code></pre></div><p><img src="/assets/img/image-20200807195048335.f449a4ab.png" alt="image-20200807195048335"></p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">cat</span> .ssh/id_rsa.pub
</code></pre></div><p>将打印的内容复制下来，添加到远程主机的<code>~/.ssh/authorized_keys</code>中，如果不存在则自己新建一个，理论上应该可以远程登录了</p></li> <li><p>安装docker</p> <p>添加 Docker 的官方 GPG 密钥：</p></li></ol> <div class="language- extra-class"><pre class="language-text"><code>curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
</code></pre></div><p>​	使用以下指令设置稳定版仓库</p> <div class="language- extra-class"><pre class="language-text"><code>sudo add-apt-repository &quot;deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/ $(lsb_release -cs) stable&quot;
</code></pre></div><p>更新索引</p> <div class="language- extra-class"><pre class="language-text"><code>sudo apt update
</code></pre></div><p>安装docker</p> <div class="language- extra-class"><pre class="language-text"><code>sudo apt install docker-ce docker-ce-cli containerd.io
</code></pre></div><p>启动docker</p> <div class="language- extra-class"><pre class="language-text"><code>service docker start
</code></pre></div><p>开机自启动docker</p> <div class="language- extra-class"><pre class="language-text"><code> systemctl enable docker
</code></pre></div><p>测试是否正常</p> <div class="language- extra-class"><pre class="language-text"><code>sudo docker run hello-world
</code></pre></div><p><img src="/assets/img/image-20200806182317228.f9573be8.png" alt="image-20200806182317228"></p> <p>非root用户使用docker</p> <div class="language- extra-class"><pre class="language-text"><code>sudo usermod -aG docker ratton
</code></pre></div><p>搜索镜像</p> <div class="language- extra-class"><pre class="language-text"><code>docker search &lt;image-name&gt;
</code></pre></div><p>可以在<a href="https://hub.docker.com/" target="_blank" rel="noopener noreferrer">官网<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>搜索镜像，查看所有的版本号，确定想要下载的镜像</p> <p>下载mysql</p> <div class="language- extra-class"><pre class="language-text"><code>docker pull mysql
</code></pre></div><p>默认下载最新的，可以指定版本号下载</p> <div class="language- extra-class"><pre class="language-text"><code>docker pull mysql:5.7
</code></pre></div><p>下载tomcat</p> <div class="language- extra-class"><pre class="language-text"><code>docker pull tomcat
</code></pre></div><table><thead><tr><th>操作</th> <th>命令示例</th> <th>说明</th></tr></thead> <tbody><tr><td>查看本地镜像</td> <td>docker images</td> <td></td></tr> <tr><td>启动一个容器</td> <td>docker run --name myredis -d redis -p 6379:6379</td> <td>后台运行redis容器，容器定义为myredis，-p参数表示端口映射，如果不确定映射的端口号可以先不加-p，运行后通过docker ps查看端口号 -p 8888:8080表示容器的8080端口映射到虚拟机的8888</td></tr> <tr><td>删除镜像</td> <td>docker rmi 容器id</td> <td></td></tr> <tr><td>查看容器日志</td> <td>docker logs 容器名或容器id</td> <td></td></tr> <tr><td>查看运行中的容器</td> <td>docker ps</td> <td></td></tr> <tr><td>停止容器</td> <td>docker stop &lt; image-id &gt;</td> <td>如果无法停止，尝试<code>sudo aa-remove-unknown</code></td></tr> <tr><td>删除容器</td> <td>docker rm &lt; image-id&gt;</td> <td>删除前需要停止容器</td></tr></tbody></table> <p><s>如果还是访问不了tomcat，尝试关闭linux防火墙</s></p> <h3 id="创建mysql容器"><a href="#创建mysql容器" class="header-anchor">#</a> 创建mysql容器</h3> <p>去官网<a href="https://hub.docker.com/s" target="_blank" rel="noopener noreferrer">dockerhub<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>查mysql的使用说明，发现运行容器需要指定密码</p> <div class="language-bash extra-class"><pre class="language-bash"><code>docker run --name mysql-5.7 -p <span class="token number">3306</span>:3306 -v /home/ratton/mysql/data:/var/lib/mysql  -v /home/ratton/mysql/conf:/etc/mysql/conf.d -v /home/ratton/mysql/logs:/var/log -e <span class="token assign-left variable">MYSQL_ROOT_PASSWORD</span><span class="token operator">=</span>YWRtaW4yMzM<span class="token operator">=</span> -d mysql:5.7 --character-set-server<span class="token operator">=</span>utf8mb4 --collation-server<span class="token operator">=</span>utf8mb4_unicode_ci
</code></pre></div><p>进入mysql-client</p> <div class="language- extra-class"><pre class="language-text"><code> docker exec -it mysql-5.7 mysql -uroot -pYWRtaW4yMzM=
</code></pre></div><p>创建用户</p> <div class="language-mysql extra-class"><pre class="language-text"><code>CREATE USER 'developer'@'%';
# 创建一个账号，用来进行远程访问；
# '%'代表的是所有IP，如果可以尽量设置指定 IP 或 IP 段
GRANT ALL ON *.* TO 'developer'@'%';
# 赋予所有权限给之前创建的账号
FLUSH PRIVILEGES;
# 刷新权限
</code></pre></div><h3 id="创建tomcat容器"><a href="#创建tomcat容器" class="header-anchor">#</a> 创建tomcat容器</h3> <div class="language-bash extra-class"><pre class="language-bash"><code> docker run -d -p <span class="token number">8080</span>:8080 --name tomcat tomcat
</code></pre></div><p>将docker的8080端口映射到了虚拟机的8080端口，所以要注意了，在宿主机上的localhost和虚拟机ip是不一致的，如果按照思维惯性在宿主机敲localhost加端口号是没有用的</p> <h3 id="创建redis容器"><a href="#创建redis容器" class="header-anchor">#</a> 创建redis容器</h3> <div class="language-bash extra-class"><pre class="language-bash"><code> docker run --name redis -p <span class="token number">6379</span>:6379 -d redis redis-server --appendonly <span class="token function">yes</span>
</code></pre></div><p>本地目录和docker目录文件传输</p> <div class="language- extra-class"><pre class="language-text"><code>docker cp 虚拟机目录 容器id/目录 
docker cp  容器id/目录  虚拟机目录
</code></pre></div><p>下载消息中间件</p> <div class="language- extra-class"><pre class="language-text"><code>docker pull rabbitmq
</code></pre></div><p>下载全文检索</p> <div class="language- extra-class"><pre class="language-text"><code>docker pull itzg/elasticsearch
</code></pre></div><h1 id="配置springboot数据源"><a href="#配置springboot数据源" class="header-anchor">#</a> 配置springboot数据源</h1> <p>引入maven依赖</p> <div class="language-xml extra-class"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.alibaba<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>druid<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>1.1.23<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><p>springboot2.3.1.RELEASE默认数据源</p> <div class="language- extra-class"><pre class="language-text"><code>class com.zaxxer.hikari.HikariDataSource
</code></pre></div><p>使用druid数据源</p> <div class="language- extra-class"><pre class="language-text"><code>spring:
	datasource:
		type: com.alibaba.druid.pool.DruidDataSource
</code></pre></div><h2 id="服务器服务一键启动脚本"><a href="#服务器服务一键启动脚本" class="header-anchor">#</a> 服务器服务一键启动脚本</h2> <div class="language-mysql extra-class"><pre class="language-text"><code>docker start mysql
docker start tomcat
docker start redis
</code></pre></div></div> <footer class="page-edit"><!----> <!----> <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh"><img alt="知识共享许可协议" src="" style="border-width:0"></a><br>本作品采用<a rel="license" href="http://creativecommons.org/licenses/by/4.0/">知识共享署名 4.0 国际许可协议</a>进行许可。

   
</footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/配置记录/Ubuntu１８．０４新手踩雷.html" class="prev">
        ubuntu18.04 新手踩雷
      </a></span> <span class="next"><a href="/配置记录/运行tensorflow使用gpu加速.html">
        运行tensorflow使用gpu加速
      </a>
      →
    </span></p></div>  <footer style="text-align:center;"><a href="https://beian.miit.gov.cn">
    粤ICP备2021020303号</a></footer></main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.54ea76a2.js" defer></script><script src="/assets/js/2.c554ece5.js" defer></script><script src="/assets/js/15.1adeebc5.js" defer></script>
  </body>
</html>
